package leetcode.slidwidow;

public class Lc2379 {



    public int minimumRecolors(String blocks, int k) {

        int ans = 0, cnt = 0;
        int j = 0;
        for (; j < k; j++) {
            if (blocks.charAt(j) == 'B')
                cnt++;
        }
        int i = 1;
        ans = cnt;
        while (i <= j && j < blocks.length()) {
            if (blocks.charAt(i-1) == 'B')
                cnt--;
            if (blocks.charAt(j) == 'B') {
                cnt++;
                ans = Math.max(ans, cnt);
            }
            i++;
            j++;
        }
        return k - ans;
    }





}
